﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     UserInfo业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class UserInfoSqlMapDao : BaseSqlMapDao, IUserInfoDao
    {
        private static UserInfoSqlMapDao instance = null;
        private static object syncRoot = new object();

        private UserInfoSqlMapDao()
        {
            //
            // TODO: 此处添加UserInfoSqlMapDao的构造函数
            //
        }
        public static IUserInfoDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new UserInfoSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectUserInfoByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<UserInfo> GetList()
        {
            try
            {
                return ExecuteQueryForList<UserInfo>("SelectUserInfo", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<UserInfo> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<UserInfo>("SelectUserInfoByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public UserInfo GetDetail(UserInfo user)
        {
            try
            { 
                return ExecuteQueryForObject<UserInfo>("SelectUserInfo", user) as UserInfo;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 根据用户信息查询数据库中的记录
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public IList GetUserByUserInfo(UserInfo userinfo)
        {
            return ExecuteQueryForList("SelectByUserInfo", userinfo);
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object Add(UserInfo userinfo)
        {
            try
            {
                return ExecuteInsert("InsertUserInfo", userinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public int Update(UserInfo userinfo)
        {
            try
            {
                return ExecuteUpdate("UpdateUserInfo", userinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public int Delete(System.String userid)
        {
            try
            {
                return ExecuteDelete("DeleteUserInfo", userid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public int Delete(UserInfo userinfo)
        {
            try
            {
                return ExecuteDelete("DeleteUserInfo", userinfo.UserID);
            }
            catch
            {
                throw;
            }
        }


        #region##通过用户名得到用户ID
        /// <summary>
        /// 通过用户名得到用户ID
        /// 创建人：Wilson
        /// 创建时间：2011-10-27
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public string GetUserIdByUserName(string username)
        {
            try
            {
                AUV5.Model.UserInfo user = new UserInfo();
                user.UserName = username;
                return Convert.ToString(ExecuteQueryForObject("SelectUserIDByUserName", user));
            }
            catch
            {
                
                throw;
            }
        }
        #endregion

        /// <summary>
        /// 获取分页用户数据
        /// </summary>
        /// <param name="pager"></param>
        /// <returns></returns>
        public IList<UserInfo> GetPagedList(NetPager pager) 
        {
            try
            {
                return ExecuteQueryForList<UserInfo>("GetPagedUser", pager);
            }
            catch 
            {
                
                throw;
            }   
        }

    }
}
